﻿<cfsilent>
	<cfscript>
		
		examId = event.getArg("EX");
		termId = event.getArg("TID");
		
		propAdvice = getProperty("serviceFactory").getBean("cetEntryPropertyAdvice");
		
		sql = "SELECT 
				t_student.stu_id, t_student.stu_name, 
				t_class.cls_name, t_class.grade, 
				t_subject.sbj_name, 
				t_institute.institute_name, 
				t_cet.exam_id, t_cet.exam_name, t_cet.exam_charge, 
				entry_prop 
				FROM t_cet_entry 
				INNER JOIN t_cet ON t_cet.exam_id = t_cet_entry.exam_id 
				INNER JOIN t_student ON t_cet_entry.stu_id = t_student.stu_id 
				INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
				INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
				INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					t_cet_entry.term_id = :termId 
					AND 
					t_cet_entry.exam_id = :examId 
					AND 
					t_cet_entry.is_charged = '0' 
				ORDER BY t_student.stu_id ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );

		rs_student = queryObj.execute( sql=sql ).getResult();


		temFile = GetTempDirectory() & createUUID() & ".xls";
		downFile = URLEncodedFormat( termId & "学期," & examId & "缴费学生清单", "utf-8");

		excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
		/* 创建工作簿 */
		spreadsheetObj = excel.SpreadSheetNew("缴费学生清单", false);
		
		/* 添加表头 */
		excel.SpreadsheetAddrow(spreadsheetObj, "学号,姓名,班级,年级,专业,学院,报考科目,语言级别,报名费,现金,银行代扣,网银");
		
		row = 1;
		
		for ( a=1; a LTE rs_student.recordCount; a++ ) {
			
			row++;
			
			/* 构建考生数据 */
			rowData = rs_student["stu_id"][a]
						& "," & rs_student["stu_name"][a]
						& "," & rs_student["cls_name"][a]
						& "," & rs_student["grade"][a]
						& "," & rs_student["sbj_name"][a]
						& "," & rs_student["institute_name"][a]
						& "," & rs_student["exam_id"][a]
						& "," & rs_student["exam_name"][a]
						& "," & numberFormat( rs_student["exam_charge"][a], "__.__") 
						& ", , , ";

			/* 写入考生信息 */
			excel.SpreadsheetAddrow(spreadsheetObj, rowData);
			
			propAdvice.parseProperty( rs_student["entry_prop"][a] );
			
			if ( propAdvice.getCash() ) {
				excel.SpreadsheetSetCellValue(spreadsheetObj, "是", row, 10);
			}
			if ( propAdvice.getBankInstead() ) {
				excel.SpreadsheetSetCellValue(spreadsheetObj, "是", row, 11);
			}
			if ( propAdvice.getBankOnline() ) {
				excel.SpreadsheetSetCellValue(spreadsheetObj, "是", row, 12);
			}
			
			
		}
		
		
		excel.SpreadSheetWrite(spreadsheetObj, temFile, true);
		
	</cfscript>

	<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
	<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	

</cfsilent>